<?php
/**
 * Created by PhpStorm.
 * User: ttl
 * Date: 2019/5/20
 * Time: 11:13
 */

namespace app\api\controller;
use app\common\logic\BuildsLogic;

class Builds extends Base
{

    /*
     * 初始化操作
     */
//    public function _initialize()
//    {
//        $this->nocheckArr = ['upload_img'];
//        parent::_initialize();
//    }

    /**
     * 一些配置
     */
    public function get_build_config(){
        $b_logic = new BuildsLogic();
        $this->returnMsg('1','',$b_logic->get_build_config());
    }

    /**
     * 按照类型查询设施
     */
    public function get_builds(){
        $b_logic = new BuildsLogic();
        $this->returnMsg('1','',$b_logic->get_builds());
    }

    /**
     * 对应建筑详情
     */
    public function build_msg(){
        $b_logic = new BuildsLogic();
        $this->returnMsg('1','',$b_logic->build_msg());
    }

    /**
     *获得评论列表
     */
    public function build_commits(){
        $b_logic = new BuildsLogic();
        $this->returnMsg('1','',$b_logic->build_commits());
    }

    /***
     * 提交评论
     */
    public function submit_commit(){
        $b_logic = new BuildsLogic();
        $result = $b_logic->submit_commit($this->user);
        $this->returnMsg($result['status'],$result['msg'],$result['result']);
    }

    /**
     * 上传图片
     */
    public function upload_img(){
        ob_end_clean();
        $file = request()->file('file');
        $imgtop = 'upload/comment/';
        $pic_path = config('COMMPICPATH ');
//        echo $pic_path . $imgtop;
//        return $file;
        $info = $file->move($pic_path . $imgtop);
        if($info){
            $imageurl = $info->getSaveName();
            $imageurl = preg_replace('/\\\\/', '/', $imageurl);

            $allurls = $imgtop.$imageurl;

            $this->returnMsg('1','',$allurls);
        }
        else{
            $this->returnMsg('-1',$file->getError());
        }
    }
}